package leecode

func Jump(nums []int) int {
	var result int
	maxReach := 0  //记录当前一步能够到达的最远位置
	nextReach := 0 //下一步能都到达的最远位置
	for i := 0; i < len(nums)-1; i++ {
		nextReach = max(nextReach, i+nums[i])
		if maxReach == i {
			//走到当前最远下标
			maxReach = nextReach
			result++
		}
	}
	return result
}
